const categoryHttp = require("../../utils/category")
Page({
  data: {
    detail: [],
    option1: [
      { text: '全部商品', value: 0 },

    ],
    option2: [
      { text: '默认排序', value: 'a' },
      { text: '好评排序', value: 'b' },
      { text: '销量排序', value: 'c' },
    ],
    value1: 0,
    value2: 'a',
  },
  onClickLeft() {
    wx.showToast({ title: '点击返回', icon: 'none' });
    wx.navigateBack()
  },
  async onLoad(options) {
    var { id } = options;
    var fn = this.handleId(id);
    var res = await categoryHttp[fn]();
    console.log(res.data.res);
    var arr = res.data.res;
    var detail = [];
    arr.forEach(item => {
      var { _id, price, name, Count, isLike, pic, title } = item;
      detail.push({
        _id,
        pic,
        name: name.slice(3, 18),
        Count,
        isLike,
        price,
        title
      })
      this.setData({
        detail
      })
    })
  },
  handleId(id) {
    if (id == "woman") {
      return "getWoman"
    } else if (id == "man") {
      return "getMan"
    } else if (id == "spring") {
      return "getSpring"
    } else if (id == "summer") {
      return "getSummer"
    } else if (id == "autumn") {
      return "getAutumn"
    } else if (id == "winter") {
      return "getWinter"
    }
  },
  handleClick(event) {
    console.log(event.currentTarget.dataset);
    var { aid } = event.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/cateaory_detail/index?id=${aid}`,
    });
  }
})